<?php /*a:3:{s:73:"D:/phpstudy_pro/WWW/stop/public/plugins/pay/admin/view/config/wechat.html";i:1678156414;s:58:"D:\phpstudy_pro\WWW\stop\app\admin\view\common\header.html";i:1680353648;s:58:"D:\phpstudy_pro\WWW\stop\app\admin\view\common\footer.html";i:1650617578;}*/ ?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no">
<title>OneKeyAdmin后台管理系统</title>
<link rel="icon" href="/upload/favicon.ico"> 
<link rel="stylesheet" type="text/css" href="/admin/css/element.min.css?v=<?php echo config('app.version'); ?>">
<link rel="stylesheet" type="text/css" href="/admin/css/onekey.min.css?v=<?php echo config('app.version'); ?>">
<script type="text/javascript" src="/admin/js/jquery.min.js?v=<?php echo config('app.version'); ?>"></script>
<script type="text/javascript" src="/admin/js/vue.min.js?v=<?php echo config('app.version'); ?>"></script>
<script type="text/javascript" src="/admin/js/element.min.js?v=<?php echo config('app.version'); ?>"></script>
<script type="text/javascript" src="/admin/js/sortable.min.js?v=<?php echo config('app.version'); ?>"></script>
<script type="text/javascript" src="/admin/js/vuedraggable.min.js?v=<?php echo config('app.version'); ?>"></script>
<script type="text/javascript" src="/admin/js/common.js?v=<?php echo config('app.version'); ?>"></script>
<script type="text/javascript" src="/admin/js/component.js?v=<?php echo config('app.version'); ?>"></script>
<script type="text/javascript" src="/admin/js/nprogress.js?v=<?php echo config('app.version'); ?>"></script>
</head>
<body>
<div id="app" v-cloak>
    <div class="el-pane-warp">
		<el-form :model="config" :rules="configRules" ref="config" label-width="120px" style="background-color: #fff;padding: 20px;">
			<el-form-item label="APPID" prop="app_id">
				<el-input v-model="config.app_id"></el-input>
				绑定支付的APPID（必须配置，开户邮件中可查看）
			</el-form-item>
			<el-form-item label="MCHID商户号" prop="mch_id">
				<el-input v-model="config.mch_id"></el-input>
				商户号（必须配置，开户邮件中可查看）
			</el-form-item>
			<el-form-item label="商户支付密钥" prop="key">
				<el-input type="password" v-model="config.key" show-password></el-input>
				商户支付密钥，参考开户邮件设置（必须配置，登录商户平台自行设置）, 请妥善保管， 避免密钥泄露。获取地址：
				<a href="https://pay.weixin.qq.com/index.php/account/api_cert" target="_blank">点击获取</a>
			</el-form-item>
			<el-form-item label="公众帐号secert" prop="app_secret">
				<el-input type="password" v-model="config.app_secret" show-password></el-input>
				APPSECRET：公众帐号secert（仅JSAPI支付的时候需要配置， 登录公众平台，进入开发者中心可设置）， 请妥善保管， 避免密钥泄露。
				获取地址：
				<a href="https://mp.weixin.qq.com/advanced/advanced?action=dev&t=advanced/dev&token=2005451881&lang=zh_CN" target="_blank">点击获取</a>
			</el-form-item>
			<el-form-item label="证书上传：" prop="apiclient_cert">
				<el-tag v-if="config.apiclient_cert" type="success">已上传证书</el-tag>
	        	<el-tag v-else type="danger">未上传证书</el-tag>
	            <el-upload
	                class="file-upload"
	                action=""
	                :show-file-list="false"
	                :before-upload="beforeApiclientCertUpload">
	                <el-button>apiclient_cert证书上传</el-button>
	            </el-upload>
	        </el-form-item>
	        <el-form-item label="证书上传：" prop="apiclient_key">
	        	<el-tag v-if="config.apiclient_key" type="success">已上传证书</el-tag>
	        	<el-tag v-else type="danger">未上传证书</el-tag>
	            <el-upload
	                class="file-upload"
	                action=""
	                :show-file-list="false"
	                :before-upload="beforeApiclientKeyUpload">
	                <el-button>apiclient_key证书上传</el-button>
	            </el-upload>
	        </el-form-item>
	        <el-form-item label="开启状态" prop="open">
				<el-switch
					v-model="config.open"
					active-color="#13ce66"
					inactive-color="#ff4949"
					:active-value="1"
					:inactive-value="0">
				</el-switch>
			</el-form-item>
			<el-form-item v-if="qrCode != ''" label="支付二维码：">
				<div class="image" v-html="qrCode"></div>
			</el-form-item>
		</el-form>
		<div class="el-bottom">
			<el-button size="medium" type="primary" @click="submit" :loading="loading">保 存</el-button>
			<el-button size="medium" type="warning" @click="test" :loading="qrcodeLoading">测 试</el-button>
		</div>
	</div>
</div>
<script>
	new Vue({
	    el: '#app',
	    data() {
	        return {
	        	url: 'pay/config/wechat',
	        	testUrl: 'pay/test/wechat',
	        	qrCode: "",
	        	qrcodeLoading: false,
	        	param: new FormData(),
	            config: <?php echo json_encode($config); ?>,
	            loading: false,
	            configRules: {
	                app_id: [
	                    { required: true, message: '请输入您的APPID', trigger: 'blur' },
	                ],
	                mch_id: [
	                    { required: true, message: '请输入您的商户ID', trigger: 'blur' },
	                ],
	                key: [
	                    { required: true, message: '请输入您的商户支付密钥', trigger: 'blur' },
	                ],
	                app_secret: [
	                    { required: true, message: '请输入您的公众帐号secert', trigger: 'blur' },
	                ],
	                apiclient_cert: [
	                    { required: true, message: '请上传您的apiclient_cert证书', trigger: 'blur' },
	                ],
	                apiclient_key: [
	                    { required: true, message: '请上传您的apiclient_key证书', trigger: 'blur' },
	                ],
	                open: [
	                    { required: true, message: '请输入', trigger: 'blur' },
	                ],
	            },
	        }
	    },
	    methods: {
	    	/**
	    	 * 提交
	    	 */
	    	submit() {
	    		let self = this;
	            self.$refs.config.validate((valid) => {
	                if (valid) {
	                    self.loading = true;
	                    self.param.append('app_id', self.config.app_id);
	                    self.param.append('mch_id', self.config.mch_id);
	                    self.param.append('key', self.config.key);
	                    self.param.append('app_secret', self.config.app_secret);
	                    self.param.append('open', self.config.open);
	                    $.ajax({
                            url: admin_url(self.url),
                            type: 'post',
                            data: self.param,
                            async:false,
                            cache:false,
                            contentType:false,
                            processData:false,
                            success:function(res) {
                                if (res.status === 'login') {
                                    store.setLoginDialog(true); // 打开登录弹窗
                                    self.loading = false;
                                } else {
                                	self.config = Object.assign({}, self.config, {apiclient_cert: true, apiclient_key: true});
                                    self.$notify({ showClose: true, message: res.message, type: res.status});
                                    self.loading = false;
                                }
                            },
                            error:function(res) {
                                self.$notify({ showClose: true, message: '系统错误', type: 'error'});
                                self.loading = false;
                            }
                        })
	                } else {
	                    return false;
	                }
	            });
	    	},
	    	/**
	    	 * 测试
	    	 */
	    	test() {
	    		let self = this;
	    		self.qrcodeLoading = true;
	    		request.post(self.testUrl, {}, function(res) {
	                if (res.status === 'success') {
	                    self.qrCode = res.data;
	                } else {
	                    self.$notify({ showClose: true, message: res.message, type: res.status});
	                }
	                self.qrcodeLoading = false;
	            });
	    	},
	    	/**
             * 准备上传
             */
            beforeApiclientCertUpload(item) {
                let windowURL = window.URL || window.webkitURL;
                this.config = Object.assign({}, this.config, {apiclient_cert: windowURL.createObjectURL(item)});
                this.param.append('apiclient_cert', item);
                return false;
            },
            /**
             * 准备上传
             */
            beforeApiclientKeyUpload(item) {
                let windowURL = window.URL || window.webkitURL;
                this.config = Object.assign({}, this.config, {apiclient_key: windowURL.createObjectURL(item)});
                this.param.append('apiclient_key', item);
                return false;
            },
	    }
	})
</script>
</body>
</html>